package com.example.musicdemo.presenter.impl

import com.example.musicdemo.base.BaseListPresenter
import com.example.musicdemo.base.BaseView
import com.example.musicdemo.model.SongListBean
import com.example.musicdemo.net.HomeRequest
import com.example.musicdemo.net.ResponseHandler
import com.example.musicdemo.presenter.interf.HomePresenter

class HomePresenterImp(private var homeView: BaseView<List<SongListBean>>?) : HomePresenter,
    ResponseHandler<List<SongListBean>> {


    /**
     * 初始化数据或者刷新数据
     */
    override fun loadData() {

        HomeRequest(BaseListPresenter.TYPE_INIT_OR_REFRESH, 0, this).excute()


    }


    override fun destroyView() {

        if (homeView != null) {
            homeView = null
        }
    }


    /**
     * 加载更多数据
     */
    override fun loadMore(offset: Int) {

        HomeRequest(BaseListPresenter.TYPE_LOAD_MORE, offset, this).excute()


    }

    override fun onError(type: Int, msg: String) {
        homeView?.onError(msg)

    }

    override fun onSuccess(type: Int, result: List<SongListBean>) {
        when (type) {
            BaseListPresenter.TYPE_INIT_OR_REFRESH -> homeView?.loadSuccess(result)
            BaseListPresenter.TYPE_LOAD_MORE -> homeView?.loadMore(result)
        }

    }


}